package com.xin.jdbc;

import javax.xml.transform.Result;
import java.sql.*;

/*
用来弄出这个表的所有信息
 */
public class jdbctest_03 {
    public static void main(String[] args) {
        Connection conn = null;
        Statement sta = null;
        ResultSet re = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
           conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/student_manage", "root", "856736");

//            String url="jdbc:mysql://127.0.0.1:3306/student_manage";
//            String user="root";
//            String password="856736";
//            conn = DriverManager.getConnection(url,user,password);
            sta = conn.createStatement();
             String sql = "select * from stu_information";
            ;
            //这个方法返回一个ResulSet的对象，这个对象里应该有很多方法，来弄出查完的结果
            re = sta.executeQuery(sql);
            //处理查询结果集
            while (re.next()) {
                System.out.println(re.getInt("stu_id") + re.getString("stu_name"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (re != null) {
                try {
                    re.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (sta != null) {
                try {
                    sta.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
